<template>
  <q-page class="cc-admin">
    <div class="col bg-white shadow-2 q-pa-md q-ma-sm">
      <q-table flat color="primary" class="cross_table" separator="cell" :columns="columns" :data="list" row-key="id" :pagination.sync="pagination" :visible-columns="group" @request="query" :rows-per-page-options="[10, 20, 50, 100]" selection="multiple" :selected.sync="selected">
        <template v-slot:top="">
          <div class="row no-wrap full-width">
            <q-input clearable outlined dense placeholder="请输入关键字搜索" class="on-left" @input="query" debounce="500" v-model="key">
              <template #append>
                <q-btn flat round icon="search" color="primary" @click="query" :loading="loading">
                  <q-tooltip>搜索</q-tooltip>
                </q-btn>
              </template>
            </q-input>
            <q-space />
          </div>
        </template>
        <template #body-cell-opt="props">
          <q-td :props="props" :auto-width="true">
            <q-btn flat round dense color="primary" icon="edit" @click="edit(props.row)"> <q-tooltip>编辑</q-tooltip></q-btn>
            <!-- <q-btn flat round dense color="primary" icon="mdi-content-copy" @click="copy(props.row)">
              <q-tooltip>复制</q-tooltip>
            </q-btn> -->
            <q-btn flat round dense color="primary" icon="mdi-file-search-outline" @click="edit(props.row)">
              <q-tooltip>查看</q-tooltip>
            </q-btn>
            <btn-del label="试卷" @confirm="del(props.row)" />
          </q-td>
        </template>
      </q-table>
    </div>

    <q-dialog maximized flat persistent ref="dialog">
      <q-form @submit="submit2" class="dialog_card column">
        <h5 class="view_title justify-between q-px-md">
          查看试卷
          <q-btn dense outline round icon="clear" size="sm" v-close-popup />
        </h5>
        <q-scroll-area class="col">
          <div class="row q-col-gutter-x-md dialog_form q-pa-md">
            <div class="col-12">
              <h5>一、选择题</h5>
              <!-- <q-input outlined dense v-model="" type="text" /> -->
            </div>
            <div class="col-12 q-pb-md" v-for="(item, index) in this.form.choiceQuestionsList" :key="item.id">
              <div>{{ index + 1 + '.' + item.question }}</div>
              <q-radio disable v-model="form.choiceAnswer[index]" color="cyan" :label="'A: ' + item.optionA" val="A" />
              <q-radio disable v-model="form.choiceAnswer[index]" color="cyan" :label="'B: ' + item.optionB" val="B" />
              <q-radio disable v-model="form.choiceAnswer[index]" color="cyan" :label="'C: ' + item.optionC" val="C" />
              <q-radio disable v-model="form.choiceAnswer[index]" color="cyan" :label="'D: ' + item.optionD" val="D" />
              <div class="answerdiv q-pl-xl">
                <!-- <q-input outlined dense v-model="examForm.choiceAnswer[index]" type="text" class="answer" /> -->
                <q-icon name="mdi-check-bold" color="green" size="md" v-show="item.answer == form.choiceAnswer[index]"></q-icon>
                <q-icon name="mdi-close" color="red" size="md" v-show="item.answer != form.choiceAnswer[index]"></q-icon>
              </div>
              <!-- 答案解析条件需要改为作答完毕 -->
              <h5 class="text-red-6">{{ item.analysis }}</h5>
            </div>
            <div class="col-12">
              <h5>二、多选题</h5>
              <!-- <q-input outlined dense v-model="" type="text" /> -->
            </div>
            <div class="col-12 q-pb-md" v-for="(item, index) in this.form.multiChoiceQuestionsList" :key="item.id">
              <div>{{ index + 1 + '.' + item.question + ' ' }}</div>
              <q-select :value="form.multiChoiceAnswer[index]" style="width: 30%; display: inline-block" outlined dense :options="item.option" option-label="label" multiple emit-value @input="preventValueChange" />
              <div class="answerdiv q-pl-xl" style="display: inline-block">
                <q-icon name="mdi-check-bold" color="green" size="md" v-show="form.multiChoiceResult[index] === '1'"></q-icon>
                <q-icon name="mdi-close" color="red" size="md" v-show="form.multiChoiceResult[index] === '0'"></q-icon>
                <span>答案：</span>
                {{ item.answer.join(',') }}
              </div>
              <!-- 答案解析条件需要改为作答完毕 -->
              <!-- <h5 v-if="editType === '答题'" class="text-red-6">{{ item.analysis }}</h5> -->
            </div>
            <div class="col-12">
              <h6>三、材料题</h6>
              <!-- <q-input outlined dense v-model="" type="text" /> -->
            </div>
            <div class="col-12 q-pb-md q-mb-xl" style="" v-for="(item, index2) in this.form.designAnswer" :key="item.id">
              <div style="font-weight: 800; font-size: 16px">{{ index2 + 1 + '.' + item.questionStem }}</div>
              <div class="col-12" style="height: 100%; border: 1px solid black">
                <q-splitter v-model="splitterModel">
                  <template v-slot:before>
                    <q-tabs v-model="tab2[index]" vertical class="text-teal">
                      <q-tab :name="item2.indexNum + item2.question" icon="" :label="`第${index + 1}题`" v-for="(item2, index) in item.questionList" :key="item2.id" />
                    </q-tabs>
                  </template>

                  <template v-slot:after>
                    <q-tab-panels v-model="tab2[index]" animated swipeable vertical transition-prev="jump-up" transition-next="jump-up">
                      <q-tab-panel :name="item3.indexNum + item3.question" v-for="item3 in item.questionList" :key="item3.id">
                        <div>
                          <div style="display: flex; justify-content: space-between">
                            <div class="col-12">
                              <div>{{ item3.question }}</div>
                            </div>
                            <div class="q-gutter-sm">
                              <q-radio v-model="item3.shape" checked-icon="mdi-check" unchecked-icon="" val="1" label="对"></q-radio>
                              <q-radio v-model="item3.shape" checked-icon="mdi-check" unchecked-icon="" val="0" label="错" />
                            </div>
                          </div>
                          <div class="col-12">
                            <h5>学生答案：</h5>
                            <!--                                                    大题索引  小题索引 -->
                            <q-input autogrow disable outlined dense v-model="item3.answer" readonly type="textarea" :rows="15" />
                          </div>
                          <div class="col-12">
                            <h5>实际答案：</h5>
                            <!--                                                    大题索引  小题索引 -->
                            <q-input autogrow disable outlined dense v-model="item3.realAnswer" readonly type="textarea" :rows="15" />
                          </div>
                          <div class="col-12">
                            <h5 class="text-red-6">解析：{{ item3.analysis || '无' }}</h5>
                            <!-- <q-input outlined dense v-model="item3.analysis" type="textarea" /> -->
                          </div>

                          <div class="img" style="margin-top: 10px" v-if="item3.viedoUrl">
                            <iframe :src="item3.viedoUrl" frameborder="0" allowfullscreen />
                          </div>
                        </div>
                      </q-tab-panel>
                    </q-tab-panels>
                  </template>
                </q-splitter>
              </div>
              <!-- 答案解析条件需要改为作答完毕 -->
              <h5 v-if="editType === '答题'" class="text-red-6">{{ item.analysis }}</h5>
            </div>
          </div>
        </q-scroll-area>
        <div class="row justify-center q-pa-md">
          <q-btn outline color="primary" icon="mdi-close-thick" label="关闭" v-close-popup />
          <q-btn class="q-mx-md" color="primary" icon="mdi-check-bold" label="提交" :loading="loading" type="submit2" />
        </div>
      </q-form>
    </q-dialog>
    <confirm ref="confirmDialog" :msg="confirmMsg" @confirm="deleteBatch()" />
    <q-inner-loading :showing="loading">
      <q-spinner-gears size="50px" color="primary" />
    </q-inner-loading>
  </q-page>
</template>

<script>
import { IndexMixin } from 'boot/mixins';
import { getDictLabel } from 'boot/dictionary';
import confirm from 'components/confirm';

export default {
  name: 'ViewPaper',
  mixins: [IndexMixin],
  components: {
    confirm,
  },
  data() {
    return {
      catalog: '04',
      tab: '0401',
      tab2: [],

      index: 0,
      splitterModel: 20,
      form: {
        paperName: '',
        choiceQuestionsList: [],
        choiceAnswerString: '',
        designAnswer: [],
      },
      columns: [
        {
          name: 'index',
          align: 'center',
          label: '序号',
          field: 'index',
        },
        {
          name: 'paperName',
          align: 'center',
          label: '试卷名称',
          field: 'paperName',
        },
        {
          name: 'opt',
          align: 'center',
          label: '操作',
          field: 'id',
        },
      ],
      // examForm: {
      //   id: '',
      //   choiceIds: '',
      //   paperName: '',
      //   designQuestionsListDtoList: [],
      //   designAnswer: [],
      //   choiceQuestionsList: [],
      //   choiceAnswer: [],
      // },
      showQuery: true,
      headers: [{ name: 'Authorization', value: localStorage.Authorization }],
      uploadUrl: `${process.env.SERVER_URL}${process.env.BASE_URL}/sys/common/upload`,
      imgUrl: `${process.env.SERVER_URL}${process.env.BASE_URL}/sys/common/static`,
      url: {
        list: '/exam/paperAnswerSmd/list2',
      },
    };
  },
  methods: {
    getDictLabel,
    initDict() {},
    submit2() {
      this.$axios
        .post(this.url.editshape, this.form)
        .then((r) => {
          this.$info(r.message);
          this.$refs.dialog.hide();
        })
        .finally(() => {
          this.query();
        });
    },
  },
  mounted() {
    this.initDict();
  },
};
</script>

<style lang="stylus">
.answerdiv
  white-space normal
  word-wrap break-word
  overflow-wrap break-word
  display inline-block
  .answer
    display inline-flex
    max-width 500px
</style>
